package zone.haiwen.demo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zone.haiwen.demo.dto.Passenger;
import zone.haiwen.demo.service.PassengerService;
import zone.haiwen.demo.util.JsonResult;
import zone.haiwen.demo.util.ResultCode;

/**
 * Description
 * @author zhangHaiWen
 * @date 2021/7/8 20:11
 * @return
 **/
@RestController
@RequestMapping("/test/passenger")
public class PassengerController {

    private final PassengerService passengerService;

    /**
     * Description
     * @author zhangHaiWen
     * @date 2021/7/8 20:11
     **/
    public PassengerController(PassengerService passengerService) {
        this.passengerService = passengerService;
    }

    /**
     * Description
     * @author zhangHaiWen
     * @date 2021/7/8 20:11
     * @return zone.haiwen.demo.util.JsonResult
     **/
    @GetMapping("/createTable")
    public JsonResult createTable() {
        this.passengerService.createTable();
        return new JsonResult(ResultCode.SUCCESS);
    }

    /**
     * Description
     * @author zhangHaiWen
     * @date 2021/7/8 20:12
     * @return zone.haiwen.demo.util.JsonResult
     **/
    @GetMapping("/insert")
    public JsonResult insert(Long id, String name, String gender, String age, String gmtCreate, String gmtModified) {
        this.passengerService.insert(id, name, gender, age, gmtCreate, gmtModified);
        return new JsonResult(ResultCode.SUCCESS);
    }

    /**
     * Description
     * @author zhangHaiWen
     * @date 2021/7/8 20:12
     * @return zone.haiwen.demo.util.JsonResult
     **/
    @GetMapping("/getPassengerByName")
    public JsonResult getPassengerByName(String name, int current, int limit) {
        IPage<Passenger> iPage = this.passengerService.getPassengerByName(name, current, limit);
        return new JsonResult(ResultCode.SUCCESS, iPage);
    }
}
